<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="供应商编号" prop="custNo">
          <el-input
            v-model="queryParams.custNo"
            placeholder="请输入供应商编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="供应商名称" prop="custName">
          <el-input
            v-model="queryParams.custName"
            placeholder="请输入供应商名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="税率" prop="cess">
          <el-input
            v-model="queryParams.cess"
            placeholder="请输入税率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="扣税类型" prop="invoice">
            <el-select v-model="queryParams.invoice" placeholder="请输入扣税类型" clearable size="small">
          <el-option v-for="dict in dict.type.sys_invoice" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
        </el-select>
        </el-form-item>
       
        <el-form-item label="创建人姓名" prop="createStaffName">
          <el-input
            v-model="queryParams.createStaffName"
            placeholder="请输入创建人姓名"
            clearable
            
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="创建日期" prop="createStaffDate">
          <el-date-picker clearable
            v-model="queryParams.createStaffDate"
            type="date"
            
            value-format="yyyy-MM-dd"
            placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改日期" prop="modifyDate">
          <el-date-picker clearable
            v-model="queryParams.modifyDate"
            type="date"
            
            value-format="yyyy-MM-dd"
            placeholder="请选择修改日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改人姓名" prop="modifyStaffName">
          <el-input
            v-model="queryParams.modifyStaffName"
            placeholder="请输入修改人姓名"
            clearable
            
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="审核状态" prop="pass">
          <el-input
            v-model="queryParams.pass"
            placeholder="请输入审核状态"
            clearable
            
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="审核日期" prop="passDate">
          <el-date-picker clearable
            v-model="queryParams.passDate"
            type="date"
            
            value-format="yyyy-MM-dd"
            placeholder="请选择审核日期">
          </el-date-picker>
        </el-form-item>
       
        <el-form-item label="审核人姓名" prop="passStaffName">
          <el-input
            v-model="queryParams.passStaffName"
            placeholder="请输入审核人姓名"
            clearable
            
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system.cust:cust:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system.cust:cust:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system.cust:cust:remove']"
          >删除</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system.cust:cust:export']"
          >导出</el-button> -->
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="custList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="供应商ID" align="center" prop="custId" /> -->
        <el-table-column label="供应商编号" align="center" prop="custNo" />
        <el-table-column label="供应商名称" align="center" prop="custName" />
        <el-table-column label="税率" align="center" prop="cess">
          <template slot-scope="scope">
            <span>{{ parseInt(scope.row.cess * 100)+"%"}}</span>
            </template>
        </el-table-column>
        <el-table-column label="扣税类型" align="center" prop="invoice">
            <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_invoice" :value="scope.row.invoice"/>
            </template>
        </el-table-column>
     
        <el-table-column label="创建人姓名" align="center" prop="createStaffName" />
        <el-table-column label="创建日期" align="center" prop="createDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="修改日期" align="center" prop="modifyDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.modifyDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
       
        <el-table-column label="修改人姓名" align="center" prop="modifyStaffName" />
        <el-table-column label="审核状态" align="center" prop="pass">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_pass_status" :value="scope.row.pass"/>
          </template>
        </el-table-column>
        <el-table-column label="审核日期" align="center" prop="passDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.passDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
       
        <el-table-column label="审核人姓名" align="center" prop="passStaffName" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system.cust:cust:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-share"
              @click="handlePass(scope.row)"
            >{{ scope.row.pass == 1?'反审':'审核' }}</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system.cust:cust:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 添加或修改供应商资料对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-form-item label="供应商编号" prop="custNo">
            <el-input v-model="form.custNo" placeholder="请输入供应商编号" />
          </el-form-item>
          <el-form-item label="供应商名称" prop="custName">
            <el-input v-model="form.custName" placeholder="请输入供应商名称" />
          </el-form-item>
          <el-form-item label="税率" prop="cess">
            <el-input v-model="form.cess" placeholder="请输入税率" />
          </el-form-item>
          <el-form-item label="扣税类型" prop="invoice">
            <el-select v-model="form.invoice" placeholder="请输入扣税类型" clearable size="small">
              <el-option v-for="dict in dict.type.sys_invoice" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          
         
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { listCust, getCust, delCust, addCust, updateCust ,passCust} from "@/api/system/cust/cust"
  
  export default {
    dicts: ['sys_normal_disable', 'sys_invoice','sys_pass_status'],
    name: "Cust",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 供应商资料表格数据
        custList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          custNo: null,
          custName: null,
          cess: null,
          invoice: null,
          createStaffId: null,
          createStaffName: null,
          createDate: null,
          modifyDate: null,
          modifyStaffId: null,
          modifyStaffName: null,
          pass: null,
          passDate: null,
          passStaffId: null,
          passStaffName: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询供应商资料列表 */
      getList() {
        this.loading = true
        listCust(this.queryParams).then(response => {
          this.custList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          custId: null,
          custNo: null,
          custName: null,
          cess: null,
          invoice: 'B',
          createStaffId: null,
          createStaffName: null,
          createDate: null,
          modifyDate: null,
          modifyStaffId: null,
          modifyStaffName: null,
          pass: null,
          passDate: null,
          passStaffId: null,
          passStaffName: null
        }
        this.resetForm("form")
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm")
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.custId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset()
        this.open = true
        this.title = "添加供应商资料"
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset()
        const custId = row.custId
        getCust(custId).then(response => {
          this.form = response.data
          console.log('form',this.form)
          this.open = true
          this.title = "修改供应商资料"
        })
        
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.custId != null) {
              updateCust(this.form).then(response => {
                this.$modal.msgSuccess("修改成功")
                this.open = false
                this.getList()
              })
            } else {
              addCust(this.form).then(response => {
                this.$modal.msgSuccess("新增成功")
                this.open = false
                this.getList()
              })
            }
          }
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const custIds = row.custId || this.ids
        this.$modal.confirm('是否确认删除供应商资料编号为"' + custIds + '"的数据项？').then(function() {
          return delCust(custIds)
        }).then(() => {
          this.getList()
          this.$modal.msgSuccess("删除成功")
        }).catch(() => {})
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system.cust/cust/export', {
          ...this.queryParams
        }, `cust_${new Date().getTime()}.xlsx`)
      },
      handlePass(row){
        const custId = row.custId
         passCust(custId).then(response => {
         //load
         this.getList()
        })
      }
    }
  }
  </script>
  